package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.FileBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class RecordAdapter extends StkProviderMultiAdapter<FileBean> {

    public RecordAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new RecordProvider());
    }

    private boolean isEdit;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class RecordProvider extends BaseItemProvider<FileBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, FileBean bean) {
            Glide.with(getContext()).load(bean.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivRecordItemImg));
            baseViewHolder.setText(R.id.tvRecordItemName, FileUtils.getFileName(bean.getPath()));
            baseViewHolder.setText(R.id.tvRecordItemDuration, TimeUtil.getMmss(MediaUtil.getDuration(bean.getPath())));
            baseViewHolder.setText(R.id.tvRecordItemSize, ConvertUtils.byte2FitMemorySize(FileUtils.getFileLength(bean.getPath()), 1));
            if (isEdit) {
                baseViewHolder.getView(R.id.ivRecordItemSel).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivRecordItemSel).setVisibility(View.GONE);
            }
            if (bean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivRecordItemSel, R.drawable.icon_xz2);
            } else {
                baseViewHolder.setImageResource(R.id.ivRecordItemSel, R.drawable.not_sel);
            }
        }
    }

}
